package com.njitt.bysj.controller;

import com.njitt.bysj.base.BaseController;
import com.njitt.bysj.base.ResultInfo;
import com.njitt.bysj.bean.ProjectBean;
import com.njitt.bysj.bean.ProjectDesignBean;
import com.njitt.bysj.query.BomQuery;
import com.njitt.bysj.query.ProjectDesignQuery;
import com.njitt.bysj.srevice.ProjectDesignService;
import com.njitt.bysj.srevice.SaleService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @description:
 * @author: wyj
 * @time: 2022/4/14 13:12
 */
@Controller
@RequestMapping("design")
public class DesignController extends BaseController {

    @Resource
    private ProjectDesignService designService;

    @Resource
    private SaleService saleService;

    @RequestMapping("toProductionTask")
    public String toProjectPage() {
        return "design/productionTask";
    }

    @RequestMapping("selectByParams")
    @ResponseBody
    public Map<String, Object> queryAllProject(ProjectDesignQuery projectEmpQuery) {
        return designService.selectByParams(projectEmpQuery);
    }

    @RequestMapping("bom")
    public String bom() {
        return "design/bom";
    }

    @RequestMapping("assign")
    public String assign(Integer projectId, HttpServletRequest request) {
        ProjectDesignBean projectDesignBean = designService.selectProjectByProjectId(projectId);
        request.setAttribute("design", projectDesignBean);
        return "design/assign";
    }

    @RequestMapping("updateEmpByProjectDesign")
    @ResponseBody
    public ResultInfo updateEmpByProjectDesign(ProjectDesignBean projectDesignBean) {
        designService.updateEmpByProjectDesign(projectDesignBean);
        return success("success");
    }

    @RequestMapping("toAddExcel")
    public String toAddExcel(Integer id, HttpServletRequest request, Integer projectId) {
        request.setAttribute("id", id);
        ProjectBean projectBean = saleService.selectById(projectId);
        request.setAttribute("project", projectBean);
        return "design/addExcel";
    }

    @RequestMapping("bomSelectByParams")
    @ResponseBody
    public Map<String, Object> bomSelectByParams(BomQuery query) {
        System.out.println(query.getProjectNo());
        return designService.bomSelectByParams(query);
    }
}
